﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Commerce/Views/Shared/Backend.Master"
    Inherits="System.Web.Mvc.ViewPage<IEnumerable<IBusinessType>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%:"Business types".Localize()%>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h3 class="title">
        <%: "Business types".Localize()%></h3>
    <div class="command">
        <ul class="clearfix">
            <li>
                <%: Html.ActionLink("Add Business Type".Localize(), "Create", null, new { @class = "button create link-auto-dialog" })%>
            </li>
          
        </ul>
    </div>
    <div class="table-container">
        <table>
            <thead>
                <tr>
                    <th class="checkbox">
                        <input type="checkbox" title="Select All" class="select-all" />
                    </th>
                    <th>
                        <%:"Name".Localize()%>
                    </th>
                    <th>
                        <%: "Data type".Localize()%>
                    </th>
                    <th>
                        <%: "Selections".Localize()%>
                    </th>
                    <th>
                        <%: "Default values".Localize()%>
                    </th>
                    <th>
                        <%: "Control type".Localize()%>
                    </th>
                    <th class="action">
                        <%:"Edit".Localize()%>
                    </th>
                    <th class="action">
                        <%:"Delete".Localize()%>
                    </th>
                </tr>
            </thead>
            <tbody>
                <% 
                    var index = 0;
                    foreach (var item in Model)
                    {
                        index++;
                %>
                <tr <%=index % 2 == 0?"":"class='even'" %>>
                    <td>
                        <input type="checkbox" name="selected" value="<%= item.Id %>" />
                    </td>
                    <td>
                        <%: item.Name%>
                    </td>
                    <td>
                        <%: item.DataType.ToString()%>
                    </td>
                    <td>
                        <%: item.Selections%>
                    </td>
                    <td>
                        <%: item.DefaultValues%>
                    </td>
                    <td>
                        <%: item.ControlTypeName%>
                    </td>
                    <td class="action">
                        <%: Html.ActionLink(" ", "edit", "businesstype", new { id = item.Id }, new { @class = "item-edit dialog-link" })%>
                    </td>
                    <td class="action">
                        <%using (Html.BeginForm("delete", "BusinessType", FormMethod.Post, new { @class = "delete-form" }))
                          { %>
                        <%: Html.Hidden("Id", item.Id)%>
                        <input type="submit" class="delete" />
                        <%
                            }
                        %>
                    </td>
                </tr>
                <%} %>
            </tbody>
        </table>
    </div>
    <%: Html.Partial("dialog", "Business type Editor")%>
    <script type="text/javascript">

        $(document).ready(function () {

            $(".select-all").click(function () {
                var checked = $(this).attr("checked");
                $("input[name=selected]").attr("checked", checked);
            });


            $(".batch-delete").click(function (e) {
                e.preventDefault();
                data = $("input[name=selected]").serialize()
                $.fn.ajaxPost(null, $(this).attr("href"), data);
                return false;
            });

            $(".delete-form").submit(function (e) {
                e.preventDefault();
                $(this).ajaxPost();
                return false;
            });
        });
    </script>
</asp:Content>
